<?php
if ( function_exists('register_sidebar') ){
    register_sidebar(array(
		'name'=>'首页',
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<div class="ilovertitle"><h3><span class="ilovertitlespan">',
        'after_title' => '</span></h3></div>',
    ));
    register_sidebar(array(
		'name'=>'文章页',
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<div class="ilovertitle"><h3><span class="ilovertitlespan">',
        'after_title' => '</span></h3></div>',
    ));
register_sidebar(array(
		'name'=>'其它页面',
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<div class="ilovertitle"><h3><span class="ilovertitlespan">',
        'after_title' => '</span></h3></div>',
    ));
	}
if ( function_exists('register_nav_menus') ) {
	register_nav_menus(array('primary' => '头部导航栏'));
	register_nav_menus(array('bottom' => '底部导航栏'));
}

function ajax_post(){
	if(isset($_GET['action'])&& $_GET['action'] == 'ajax_post'){
		$id=$_GET['id'];query_posts("p=$id");the_post();global $more;$more=0;the_content('');
		die();
	}else{return;}
}
add_action('init', 'ajax_post');

function pagenavi( $p = 2 ) {
if ( is_singular() ) return;
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( $max_page == 1 ) return;
if ( empty( $paged ) ) $paged = 1;
echo '<span class="page-numbers">' . $paged . ' / ' . $max_page . ' </span> ';
if ( $paged > 1 ) p_link( $paged - 1, '上一页', '上一页' );
if ( $paged > $p + 1 ) p_link( 1, '最前页' );
if ( $paged > $p + 2 ) echo '<span class="page-numbers">...</span>';
for( $i = $paged - $p; $i <= $paged + $p; $i++ ) {
if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<span class='page-numbers current'>{$i}</span> " : p_link( $i );
}
if ( $paged < $max_page - $p - 1 ) echo '<span class="page-numbers">...</span>';
if ( $paged < $max_page - $p ) p_link( $max_page, '最末页' );
if ( $paged < $max_page ) p_link( $paged + 1,'下一页', '下一页' );
}
function p_link( $i, $title = '', $linktype = '' ) {
if ( $title == '' ) $title = "第 {$i} 页";
if ( $linktype == '' ) { $linktext = $i; } else { $linktext = $linktype; }
echo "<a class='page-numbers' href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}'>{$linktext}</a> ";
}
function get_img_link($post){

    $img_link = get_post_meta($post->ID, "image_thumb", true); 

    if($img_link!=""){
	  
	  echo '<a href="'; ?><?php the_permalink() ?><?php echo '"><img src="'.$img_link.'" /></a>';

    }}

	
	function comment_color($commentid) {
	$commentid=comment_ID();
	if($commentid % 2 ==0){
            $color = '#D7D7D7';
        }else{
            $color = '#FFFFFF';
        }
		
		echo $color;
	
	}
	

/*
function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment;
   global $commentcount;$page = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );$cpp=get_option('comments_per_page');if(!$commentcount) {if ($page > 1) {$commentcount = $cpp * ($page - 1);} else {$commentcount = 0;}}
?>
	<li <?php comment_class(); ?> <?php if( $depth > 1){echo ' style="margin-left:' . ceil(80/$depth) . 'px;"';} ?> id="li-comment-<?php comment_ID() ?>" >
		<div id="comment-<?php comment_ID(); ?>" class="comment-body">
			<div class="commentmeta"><?php echo get_avatar( $comment, $size = '32'); ?></div>
				<?php if ($comment->comment_approved == '0') : ?>
				<em><?php _e('Your comment is awaiting moderation.') ?></em><br />
				<?php endif; ?>
			<div class="commentmetadata">&nbsp;-&nbsp;<?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?>&nbsp;&nbsp;<span><?php if(!$parent_id = $comment->comment_parent) {printf('%1$sL', ++$commentcount);} ?><?php if( $depth > 1){printf('B%1$s', $depth-1);} ?></span></div>
			<div class="reply"><?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => __('@')))) ?></div>
			<div class="vcard"><?php printf(__('%s'), get_comment_author_link()) ?></div>
			<?php comment_text() ?>
		</div>
<?php
}
*/

// Custom Comments List. add by zww
function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    <a href="<?php comment_author_link(); ?>" class="avatar" target="_blank"><?php echo get_avatar( $comment, 43 ); ?></a>
	<div id="comment-<?php comment_ID(); ?>" class="comment_c">
		<h2>
			<?php comment_author_link(); ?>
			<?php if(function_exists('useragent_output_custom')){ ?><span class="useragent_output_custom"><?php useragent_output_custom(); ?></span> <?php } ?>
			<span class="c_time"><?php comment_date(); ?></span>
		</h2>
		<?php comment_text(); ?>
		<?php if ($comment->comment_approved == '0') : ?>
		<?php _e('您的评论正在审核。'); ?>
		<br />
		<?php endif; ?>
		<div class="reply">
			<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
		</div>
	</div>
<?php }